package br.com.persist.api;

import java.util.HashSet;
import java.util.Set;

import br.com.persist.core.condition.SimpleAttributeValueCondition;
import br.com.persist.core.value.StringValue;
import br.com.persist.core.value.Value;

public class Criteria {

	private Entity entity;
	private Set<Condition> conditions = new HashSet<Condition>();

	public Criteria(Entity entity) {
		super();
		this.entity = entity;
	}

	public Criteria() {
		super();
	}

	public Entity getEntity() {
		return entity;
	}

	public Set<Condition> getConditions() {
		return conditions;
	}

	public Criteria entity(Entity entity) {
		this.entity = entity;
		return this;
	}

	public Criteria entity(Class<?> entity) {
		this.entity = new Entity(entity.getPackage().getName(), entity.getSimpleName());
		return this;
	}

	public Criteria add(Condition condition) {
		this.conditions.add(condition);
		return this;
	}

	public Criteria with(Condition condition) {
		this.conditions.add(condition);
		return this;
	}

	public Criteria with(String attributeName, Value attributeValue) {
		this.conditions.add(new SimpleAttributeValueCondition(attributeName, attributeValue));
		return this;
	}

	public Criteria with(String attributeName, String attributeValue) {
		this.conditions.add(new SimpleAttributeValueCondition(attributeName, new StringValue(attributeValue)));
		return this;
	}
}
